/**
 * The ammo bar class, allows you to
 * draw it very fast without much thought.
 * 
 * In reality this class is never manually
 * created, it is created in tankObject.java,
 * for each tank.
 * @author Andrew
 * @creator Andrew
 *
 * LAST UPDATED 2/4/12 - Andrew
 */
public class AmmoBar {
	
	// Pictures for the ammo 1 through to 5
	private SimpleObject ammo1;
	
	private SimpleObject ammo2;
	
	private SimpleObject ammo3;
	
	private SimpleObject ammo4;
	
	private SimpleObject ammo5;
	
	// which one is selected?
	private int selected;
	
	// x and y for the bar
	private int x;
	
	private int y;
	
	// Pictures for the numbers of ammo left
	private SimpleObject ammoN1;
	private SimpleObject ammoN2;
	private SimpleObject ammoN3;
	private SimpleObject ammoN4;
	private SimpleObject ammoN5;
	
	// Constructor - needs an x y and the tank its using
	public AmmoBar(int xi, int yi, TankObject tank) {
		
		this.x = xi;
		this.y = yi;
		// draw everything in the right place
		ammo1 = new SimpleObject(xi,yi,"ab1.png");
		ammo2 = new SimpleObject(xi+25,yi,"ab5.png");
		ammo3 = new SimpleObject(xi+50,yi,"ab4.png");
		ammo4 = new SimpleObject(xi+75,yi,"ab3.png");
		ammo5 = new SimpleObject(xi+100,yi,"ab2.png");
		
		// and draw the numbers with respect to the ammo the tank has
		ammoN1 = new SimpleObject(xi,yi-20, tank.getAmmunition(0) + ".png");
		ammoN2 = new SimpleObject(xi+25,yi-20, tank.getAmmunition(1) + ".png");
		ammoN3 = new SimpleObject(xi+50,yi-20, tank.getAmmunition(2) + ".png");
		ammoN4 = new SimpleObject(xi+75,yi-20, tank.getAmmunition(3) + ".png");
		ammoN5 = new SimpleObject(xi+100,yi-20, tank.getAmmunition(4) + ".png");
		
		// and change the selected ammo
		selected = tank.getAmmo();
	}
	
	// update changes the sprites depending on, what is selected and how much ammo you have left
	public void update(TankObject tank) {
		selected = tank.getAmmo();
		if(selected == 0){
			ammo1 = new SimpleObject(x,y,"ab1s.png");
			ammo2 = new SimpleObject(x+25,y,"ab5.png");
			ammo3 = new SimpleObject(x+50,y,"ab4.png");
			ammo4 = new SimpleObject(x+75,y,"ab3.png");
			ammo5 = new SimpleObject(x+100,y,"ab2.png");
		}
		else if(selected == 1) {
			ammo1 = new SimpleObject(x,y,"ab1.png");
			ammo2 = new SimpleObject(x+25,y,"ab5s.png");
			ammo3 = new SimpleObject(x+50,y,"ab4.png");
			ammo4 = new SimpleObject(x+75,y,"ab3.png");
			ammo5 = new SimpleObject(x+100,y,"ab2.png");
		}
		else if(selected == 2) {
			ammo1 = new SimpleObject(x,y,"ab1.png");
			ammo2 = new SimpleObject(x+25,y,"ab5.png");
			ammo3 = new SimpleObject(x+50,y,"ab4s.png");
			ammo4 = new SimpleObject(x+75,y,"ab3.png");
			ammo5 = new SimpleObject(x+100,y,"ab2.png");
		}
		else if(selected == 3) {
			ammo1 = new SimpleObject(x,y,"ab1.png");
			ammo2 = new SimpleObject(x+25,y,"ab5.png");
			ammo3 = new SimpleObject(x+50,y,"ab4.png");
			ammo4 = new SimpleObject(x+75,y,"ab3s.png");
			ammo5 = new SimpleObject(x+100,y,"ab2.png");
		}
		else{
			ammo1 = new SimpleObject(x,y,"ab1.png");
			ammo2 = new SimpleObject(x+25,y,"ab5.png");
			ammo3 = new SimpleObject(x+50,y,"ab4.png");
			ammo4 = new SimpleObject(x+75,y,"ab3.png");
			ammo5 = new SimpleObject(x+100,y,"ab2s.png");
		}
		if(tank.getAmmunition(0) >= 25) {
			ammoN1 = new SimpleObject(x,y-20, "25.png");
		}
		else if(tank.getAmmunition(0) < 25) ammoN1 = new SimpleObject(x,y-20, tank.getAmmunition(0) + ".png");
		ammoN2 = new SimpleObject(x+25,y-20, tank.getAmmunition(1) + ".png");
		ammoN3 = new SimpleObject(x+50,y-20, tank.getAmmunition(2) + ".png");
		ammoN4 = new SimpleObject(x+75,y-20, tank.getAmmunition(3) + ".png");
		ammoN5 = new SimpleObject(x+100,y-20, tank.getAmmunition(4) + ".png");
		
		
	}
	
	// draws everything associated with the bar
	public void draw() {
		ammo1.draw();
		ammo2.draw();
		ammo3.draw();
		ammo4.draw();
		ammo5.draw();
		
		ammoN1.draw();
		ammoN2.draw();
		ammoN3.draw();
		ammoN4.draw();
		ammoN5.draw();
	}

}
